package com.ming.note;

import android.app.Application;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import com.hjq.bar.ITitleBarStyle;
import com.hjq.bar.TitleBar;
import com.hjq.bar.style.TitleBarNightStyle;
import com.hjq.toast.ToastUtils;
import com.ming.note.helper.ActivityStackManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;

/**
 * author : changer
 * date   : 2020/6/11
 * desc   :
 */
public class NoteApplication extends Application {

    //static 代码段可以防止内存泄露
    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.transparent, R.color.black75);//全局设置主题颜色
                return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
    }

    private static NoteApplication instance;

    public static final NoteApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;

        //初始化标题栏样式
        initTitileBarStyle();

        // Activity 栈管理初始化
        ActivityStackManager.getInstance().init(this);

        ToastUtils.init(this);
    }

    private void initTitileBarStyle() {
//        ITitleBarStyle titleBarStyle = new TitleBarNightStyle(this) {
//
//            @Override
//            public int getTitleBarHeight() {
//                return dp2px(44);
//            }
//
//            @Override
//            public Drawable getBackIcon() {
//                return getDrawable(R.drawable.arrow_white_left_title);
//            }
//
//            //设置背景为主题颜色
//            @Override
//            public Drawable getBackground() {
//                return new ColorDrawable(0xFFFF4646);
//            }
//
//            //默认不显示分割线
//            @Override
//            public boolean isLineVisible() {
//                return false;
//            }
//        };
//        TitleBar.initStyle(titleBarStyle);
    }


}
